package com.lkd.handler;


import com.lkd.business.MsgHandler;
import com.lkd.config.TopicConfig;
import com.lkd.contract.VendoutContract;
import com.lkd.contract.VendoutData;
import com.lkd.emq.Topic;
import com.lkd.exception.LogicException;
import com.lkd.service.VendingMachineService;
import com.lkd.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Topic(TopicConfig.VMS_VENDOUT_TOPIC)
public class VendoutMsgHandler implements MsgHandler {


@Autowired
  private VendingMachineService vendingMachineService;

    @Override
    public void process(String jsonMsg) throws IOException {
        //1-解析数据
        VendoutContract vdc = JsonUtil.getByJson(jsonMsg, VendoutContract.class);
        if(vdc==null){
            throw   new LogicException("参数传递错误");
        }
        VendoutData vdd = vdc.getVendoutData();
        if(vdd==null){
            throw   new LogicException("参数传递错误");
        }
       //处理出货逻辑
       vendingMachineService.vendout(vdc) ;

    }
}
